import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

// eslint-disable-next-line require-jsdoc
export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
	{
		path: "/redirect",
		component: Layout,
		meta: { hidden: true },
		children: [
			{
				path: "/redirect/:path(.*)",
				component: () => import("@/views/redirect/index.vue")
			}
		]
	},

	{
		path: "/login",
		component: () => import("@/views/Login/index.vue"),
		meta: { hidden: true, title: "登录页" }
	},
	{
		path: "/",
		component: Layout,
		redirect: "/home",
		meta: { title: "首页", icon: "homepage" },
		children: [
			{
				path: "/home",
				component: () => import("@/views/Home/index.vue"),
				name: "home",
				meta: { title: "首页", icon: "homepage", affix: true, keepAlive: false }
			},
			{
				path: "/list",
				component: () => import("@/views/List/index.vue"),
				name: "list",
				meta: {
					title: "列表页",
					icon: "homepage",
					keepAlive: false
				}
			},
			{
				path: "/homeDetail",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail1",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail1",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail2",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail2",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail3",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail3",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail4",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail4",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail5",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail5",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail6",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail6",
				meta: { title: "子菜单", icon: "homepage", keepAlive: true }
			},
			{
				path: "/homeDetail7",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail7",
				meta: {
					title: "子菜单子菜单子菜单子菜单子菜单子菜单",
					icon: "homepage",
					keepAlive: true
				}
			},
			{
				path: "/homeDetail8",
				component: () => import("@/views/Home/index.vue"),
				name: "homeDetail8",
				meta: {
					title:
						"子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单子菜单",
					icon: "homepage",
					keepAlive: true
				}
			},
			{
				path: "/401",
				component: () => import("@/views/error-page/401.vue"),
				meta: { title: "401", hidden: true }
			},
			{
				path: "/404",
				component: () => import("@/views/error-page/404.vue"),
				meta: { title: "404", hidden: true }
			}
		]
	},

	{
		path: "/:pathMatch(.*)*",
		meta: { hidden: true },
		component: () => import("@/views/error-page/404.vue")
	}

	// 外部链接
	// {
	//   path: "/external-link",
	//   component: Layout,
	//   children: [ {
	//       component: () => import("@/views/external-link/index.vue"),
	//       path: "https://www.cnblogs.com/haoxianrui/",
	//       meta: { title: "外部链接", icon: "link" },
	//     },
	//   ],
	// },
	// 多级嵌套路由
	/* {	
         path: '/nested',
         component: Layout,
         redirect: '/nested/level1/level2',
         name: 'Nested',
         meta: {title: '多级菜单', icon: 'nested'},
         children: [
             {
                 path: 'level1',
                 component: () => import('@/views/nested/level1/index.vue'),
                 name: 'Level1',
                 meta: {title: '菜单一级'},
                 redirect: '/nested/level1/level2',
                 children: [
                     {
                         path: 'level2',
                         component: () => import('@/views/nested/level1/level2/index.vue'),
                         name: 'Level2',
                         meta: {title: '菜单二级'},
                         redirect: '/nested/level1/level2/level3',
                         children: [
                             {
                                 path: 'level3-1',
                                 component: () => import('@/views/nested/level1/level2/level3/index1.vue'),
                                 name: 'Level3-1',
                                 meta: {title: '菜单三级-1'}
                             },
                             {
                                 path: 'level3-2',
                                 component: () => import('@/views/nested/level1/level2/level3/index2.vue'),
                                 name: 'Level3-2',
                                 meta: {title: '菜单三级-2'}
                             }
                         ]
                     }
                 ]
             },
         ]
     }*/
];

export const asyncRoutes = [
	// {
	// 	path: "/permission",
	// 	component: Layout,
	// 	redirect: "/permission/page",
	// 	alwaysShow: true, // will always show the root menu
	// 	name: "Permission",
	// 	meta: {
	// 		title: "Permission",
	// 		icon: "lock",
	// 		roles: ["admin", "editor"] // you can set roles in root nav
	// 	},
	// 	children: [
	// 		{
	// 			path: "page",
	// 			component: () => import("@/views/permission/page"),
	// 			name: "PagePermission",
	// 			meta: {
	// 				title: "Page Permission",
	// 				roles: ["admin"] // or you can only set roles in sub nav
	// 			}
	// 		},
	// 		{
	// 			path: "directive",
	// 			component: () => import("@/views/permission/directive"),
	// 			name: "DirectivePermission",
	// 			meta: {
	// 				title: "Directive Permission"
	// 				// if do not set roles, means: this page does not require permission
	// 			}
	// 		},
	// 		{
	// 			path: "role",
	// 			component: () => import("@/views/permission/role"),
	// 			name: "RolePermission",
	// 			meta: {
	// 				title: "Role Permission",
	// 				roles: ["admin"]
	// 			}
	// 		}
	// 	]
	// }
];
/**
 * 创建路由
 */
const router = createRouter({
	history: createWebHashHistory(),
	routes: constantRoutes as RouteRecordRaw[],
	// 刷新时，滚动条位置还原
	scrollBehavior: () => ({ left: 0, top: 0 })
});

/**
 * 重置路由
 */
export function resetRouter() {
	router.replace({ path: "/login" });
}

export default router;
